package com.supermap.dataservice.redis;

import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;



/**
 * @author aqua
 * @desc
 * @date 2019年05月22 14:57
 * @email 1301584033@qq.com
 */
@Configuration
public class JedisConfig extends CachingConfigurerSupport {

    private String host="127.0.0.1";

    private int port=6379;
    //超时
    private int timeout=10000;

    private String password="supermap";
    //连接池最大连接数（使用负值表示没有限制）
    private int maxActive=1024;

   //连接池中的最大空闲连接
    private int maxIdle=200;

    private int minIdle=0;
    //最大等待
    private long maxWaitMillis=10000;



    @Bean
    public JedisPool redisPoolFactory(){
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxIdle(maxIdle);
        jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
        jedisPoolConfig.setMaxTotal(maxActive);
        jedisPoolConfig.setMinIdle(minIdle);
        JedisPool jedisPool = new JedisPool(jedisPoolConfig,host,port,timeout,password);
        System.out.println("JedisPool注入成功！");
        System.out.println("redis地址：" + host + ":" + port);
        return  jedisPool;
    }

}